package com.jjw.route.controller;

import java.util.Arrays;
import java.util.Map;

import com.jjw.route.algorithm.RandomArticalAlogorithm;
import com.jjw.route.algorithm.RouteGetAlgorithm;
import com.jjw.route.to.LoginTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jjw.route.entity.UserEntity;
import com.jjw.route.service.UserService;
import com.jjw.route.utils.PageUtils;
import com.jjw.route.utils.R;

import javax.servlet.http.HttpSession;


/**
 * 
 *
 * @author jjw
 * @email 2371671097@qq.com
 * @date 2023-05-12 07:45:21
 */
@RestController
@RequestMapping("route/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("route:user:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("route:user:info")
    public R info(@PathVariable("id") Integer id){
		UserEntity user = userService.getById(id);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("route:user:save")
    public R save(@RequestBody UserEntity user){
		userService.save(user);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("route:user:update")
    public R update(@RequestBody UserEntity user){
		userService.updateById(user);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("route:user:delete")
    public R delete(@RequestBody Integer[] ids){
		userService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    @RequestMapping("/register")
    public R register(@RequestBody LoginTo loginTo){
       return userService.register(loginTo);
    }
    @RequestMapping("/login")
    public R login(@RequestBody LoginTo loginTo, HttpSession session){
        return userService.login(loginTo,session);
    }

    @GetMapping("/data")
    public R userData() {
        return userService.saveData(RandomArticalAlogorithm.arr);
    }

    @GetMapping("/sim")
    public R getSim() {
        return userService.getSim();
    }
}
